#include "SmartLevelSequenceExtensions.h"
#include "SequencerTools.h"

void USmartLevelSequenceExtensions::SmSetDisplayRate(ULevelSequence * LevelSequence, int32 Rate)
{

	UMovieScene * MovieScene = LevelSequence->GetMovieScene();
	FFrameRate DisplayRate(Rate, 1);
	MovieScene->SetDisplayRate(DisplayRate);
}

TArray<UMovieSceneFolder*>& USmartLevelSequenceExtensions::SmGetRootFolders(ULevelSequence * LevelSequence)
{
	UMovieScene * MovieScene = LevelSequence->GetMovieScene();
	return MovieScene->GetRootFolders();
}

void USmartLevelSequenceExtensions::SmRemoveRootFolder(ULevelSequence * LevelSequence, FString Name) {
	UMovieScene * MovieScene = LevelSequence->GetMovieScene();
	TArray<UMovieSceneFolder*>& RootFolders = MovieScene->GetRootFolders();
	for (UMovieSceneFolder* Folder : RootFolders) {
		if (Folder->GetFolderName() == FName(*Name)) {
			RootFolders.Remove(Folder);
			break;
		}
	}
}

UMovieSceneFolder * USmartLevelSequenceExtensions::SmAddRootFolder(ULevelSequence * LevelSequence, FString Name)
{
	UMovieScene * MovieScene = LevelSequence->GetMovieScene();
	TArray<UMovieSceneFolder*>& RootFolders = MovieScene->GetRootFolders();
	UMovieSceneFolder* Folder = NewObject<UMovieSceneFolder>(MovieScene, NAME_None, RF_Transactional);;
	Folder->SetFolderName(FName(*Name));
	RootFolders.Add(Folder);
	return Folder;
}

bool USmartLevelSequenceExtensions::SmCopyTrack(ULevelSequence* LevelSequence, UMovieSceneTrack* Track)
{
	UMovieScene * MovieScene = LevelSequence->GetMovieScene();
	return MovieScene->AddGivenMasterTrack(Track);
}

bool USmartLevelSequenceExtensions::SmImportCamera(ULevelSequence* LevelSequence, UWorld* World, UMovieSceneUserImportFBXSettings* ImportFBXSettings, const FString&  ImportFilename)
{
	const TArray<FSequencerBindingProxy> InBindings;
	return USequencerToolsFunctionLibrary::ImportLevelSequenceFBX(World, LevelSequence, InBindings, ImportFBXSettings, ImportFilename);
}


